"""
API数据模型定义
"""

from typing import Dict, List, Optional
from pydantic import BaseModel, Field


class HealthResponse(BaseModel):
    """健康检查响应模型"""
    status: str = Field(..., description="服务状态")
    version: str = Field(..., description="API版本")
    
    class Config:
        json_schema_extra = {
            "example": {
                "status": "healthy",
                "version": "1.0.0"
            }
        }


class APIInfo(BaseModel):
    """API信息响应模型"""
    message: str = Field(..., description="API名称")
    version: str = Field(..., description="API版本")
    description: str = Field(..., description="API描述")
    endpoints: Dict[str, str] = Field(..., description="可用端点")
    features: List[str] = Field(..., description="功能特性")
    
    class Config:
        json_schema_extra = {
            "example": {
                "message": "Head Detection API",
                "version": "1.0.0",
                "description": "使用YOLOv8进行人头检测，自动保存标注图片",
                "endpoints": {
                    "detect": "/detect - POST请求，检测图片中的人头数量",
                    "health": "/health - GET请求，检查API健康状态",
                    "images": "/images/{filename} - GET请求，访问标注图片"
                },
                "features": [
                    "人头检测和计数",
                    "可调节置信度阈值",
                    "自动保存标注图片",
                    "详细检测结果"
                ]
            }
        }


class ErrorResponse(BaseModel):
    """错误响应模型"""
    detail: str = Field(..., description="错误详情")
    error_code: Optional[str] = Field(None, description="错误代码")
    
    class Config:
        json_schema_extra = {
            "example": {
                "detail": "下载图片失败: Connection timeout",
                "error_code": "IMAGE_DOWNLOAD_ERROR"
            }
        }
